package com.xh.bussiness.permission.controller;

import com.xh.bussiness.permission.bean.request.UserCommonMenuRequest;
import com.xh.bussiness.permission.service.IUserCommonMenuService;
import com.xh.bussiness.permission.model.UserCommonMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import com.xh.core.bean.AjaxResult;
import com.xh.core.bean.XhPage;
import com.xh.core.constant.AjaxResultConstant;
import org.springframework.validation.annotation.Validated;

import com.xh.core.controller.BaseController;

/**
 * <p>
 * 用户常用菜单 前端控制器
 * </p>
 *
 * @author Pitt
 * @since 2020-12-03
 */
@RestController
@RequestMapping("/admin/userCommonMenu")
public class UserCommonMenuController extends BaseController {

    @Autowired
    private IUserCommonMenuService userCommonMenuService;

    /**
     * 分页数据查询
     *
     * @param page 分页对象
     * @param bean 查询条件Bean
     * @return
     */
    @PostMapping("/queryPage")
    public XhPage queryPage(XhPage page, UserCommonMenuRequest bean) {
        page = userCommonMenuService.queryUserCommonMenuPage(page, bean);
        return page;
    }

    /**
     * 数据查询
     *
     * @param bean 查询条件Bean
     * @return
     */
    @PostMapping("/query")
    public AjaxResult query(UserCommonMenuRequest bean) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, "", userCommonMenuService.queryUserCommonMenu(bean));
    }


    @RequestMapping("queryUserCommonMenuByUserId")
    public AjaxResult queryUserCommonMenuByUserId(String userId) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, userCommonMenuService.queryUserCommonMenuByUserId(userId));
    }


    /**
     * 新增和保存
     *
     * @param userCommonMenu 实体对象
     * @return
     */
    @PostMapping(value = "/saveOrUpdate")
    @Transactional
    public AjaxResult saveOrUpdate(@Validated UserCommonMenu userCommonMenu) {
        if (userCommonMenu.getId() == null) {
            userCommonMenuService.addUserCommonMenu(userCommonMenu);
        } else {
            userCommonMenuService.update(userCommonMenu);
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }

    /**
     * 删除操作
     *
     * @param id
     * @return
     */
    @PostMapping("/deleteById/{id}")
    @Transactional
    public AjaxResult deleteById(@PathVariable String id) {
        userCommonMenuService.delete(id);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }

    /**
     * 批量删除操作
     *
     * @param ids
     * @return
     */
    @PostMapping("/batchDelete")
    @Transactional
    public AjaxResult batchDelete(String[] ids) {
        userCommonMenuService.batchDelete(ids);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }


}

